package com.example.binpacking.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.binpacking.model.FunInterview;
import com.example.binpacking.model.InterviewContent;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

public interface InterviewContentMapper extends BaseMapper<InterviewContent> {
    @Update("update tbl_fun_interview_content set emotiontalk= #{emotiontalk},sleeptalk= #{sleeptalk},diettalk= #{diettalk},healthtalk= #{healthtalk},socialtalk= #{socialtalk} where id= #{id} and parentid= #{parentid}")
    int updateContentById(@Param("id") String id, @Param("parentid")String parentid,@Param("emotiontalk")String emotiontalk,
                          @Param("sleeptalk")String sleeptalk,@Param("diettalk")String diettalk,@Param("healthtalk")String healthtalk,@Param("socialtalk")String socialtalk);

    @Select("select * from tbl_fun_interview_content where id=#{id}; ")
    List<InterviewContent> selectById(@Param("id") String id);

    @Select("SET @max_orderid = (SELECT IFNULL(MAX(orderid), 0) FROM tbl_fun_interview_content)")
    void initializeMaxContentId();

    @Insert("INSERT INTO tbl_fun_interview_content (id,orderid)\n" +
            "            SELECT MAX(orderid) + 1 + 20000000000,MAX(orderid) + 1\n" +
            "            FROM tbl_fun_interview_content;")
    int insertIdAndOrderid();

    @Select("SET @max_parentid = (SELECT MAX(id) FROM tbl_fun_interview);\n")
    void initializeMaxParentid();

    @Select("SET @max_id = (SELECT MAX(id) FROM tbl_fun_interview_content);\n")
    void initializeMaxId();
    @Select("SELECT *\n" +
            "FROM tbl_fun_interview_content\n" +
            "WHERE id = (SELECT MAX(id) FROM tbl_fun_interview_content);\n")
   List<InterviewContent> content();

    @Update("UPDATE tbl_fun_interview_content\n" +
            "SET parentid = @max_parentid\n" +
            "WHERE id = @max_id;")
    int updateParentid();

    @Select("select MAX(id) from tbl_fun_interview_content; ")
    Long  selectBegin();

    @Insert("INSERT INTO tbl_fun_interview_content (id,orderid)\n" +
            "values (24000000001,4000000001)\n")
    int insertBegin();

    @Select("select * from tbl_fun_interview_content where parentid=#{parentid}; ")
    List<InterviewContent>  selectByParentid(@Param("parentid")String parentid);

    @Update("update tbl_fun_interview_content set emotiontalk= #{emotiontalk},sleeptalk= #{sleeptalk},diettalk= #{diettalk},healthtalk= #{healthtalk},socialtalk= #{socialtalk} where id= #{id} and parentid= #{parentid}")
    List<InterviewContent> updateContentByIdAndParentid(@Param("id") String id, @Param("parentid")String parentid,@Param("emotiontalk")String emotiontalk,
                          @Param("sleeptalk")String sleeptalk,@Param("diettalk")String diettalk,@Param("healthtalk")String healthtalk,@Param("socialtalk")String socialtalk);


}
